# -*- coding: utf-8 -*-

import arcpy

def construct_clause(fc_name, fieldname, with_or=False):
    if with_or:
        #clause = f" OR {fc_name}.{fieldname} IS NULL"
        clause = " OR {0}.{1} IS NULL".format(fc_name,fieldname)
    else:
        #clause = f"{fc_name}.{fieldname} IS NULL"
        clause = "{0}.{1} IS NULL".format(fc_name,fieldname)
    return clause

def select_null_fc(input_fc, fc_name):
    fields = arcpy.ListFields(input_fc)
    fieldnames = [f.name for f in fields]
    if 'OBJECTID' in fieldnames:
        fieldnames.remove('OBJECTID')
    if 'Shape' in fieldnames:
        fieldnames.remove('Shape')
    if 'pointid' in fieldnames:
        fieldnames.remove('pointid')
    if 'grid_code' in fieldnames:
        fieldnames.remove('grid_code')

    sum_clause = ""
    for f_name in fieldnames:
        if sum_clause=="":
            sum_clause = construct_clause(fc_name, f_name)
        else:
            sum_clause = sum_clause + construct_clause(fc_name, f_name, with_or=True)
    return sum_clause

if __name__=='__main__':
    # ArcGIS工具箱模式
    input_fc = arcpy.GetParameterAsText(0)
    arcpy.AddMessage(input_fc)
    # 代码模式
    # arcpy.env.workspace = "F:/GIS_RS_Data/博士论文数据.gdb"
    # input_fc = "栅格单元2013（小）_fc"

    sum_clause = select_null_fc(input_fc, fc_name=input_fc)
    print(sum_clause)
    arcpy.management.SelectLayerByAttribute(input_fc, "NEW_SELECTION", sum_clause, None)